import type { ConfigEnv, UserConfig } from 'vite'
import path from 'node:path'
import viteConfig from '@repo/vite-config'
import { merge } from 'lodash-es'
import { loadEnv } from 'vite'

export default ({ command, mode, ...reset }: ConfigEnv): UserConfig => {
  const env = loadEnv(mode, process.cwd(), '')
  console.log('--command--', command)
  console.log('--mode--', mode)
  console.log('--reset--', reset)

  const config: UserConfig = {
    resolve: {
      alias: {
        'my-ui': path.resolve(__dirname, '../../packages/ui/src'),
      },
    },
    server: {
      port: +env.VITE_PORT || 4321,
    },
  }

  return merge(viteConfig, config)
}
